/*
 * @Description: 消息页面
 * @Author: iamsmiling
 * @Date: 2021-05-25 21:37:56
 * @LastEditTime: 2021-06-13 18:20:32
 */
import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/components/image/chimera_image.dart';
import 'package:credit_business_circle/domain/remote/message/message_entity.dart';
import 'package:credit_business_circle/pages/message/message_controller.dart';
import 'package:credit_business_circle/routes/app_routes.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class MessagePage extends GetView<MessageController> {
  const MessagePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: R.color.ffffffff,
      appBar: AppBar(
        elevation: 1,
        backgroundColor: R.color.ffffffff,
        title: Text(
          "消息",
          style: TextStyle(color: R.color.ff111111, fontSize: R.dimen.sp15),
        ),
        actions: [
          IconButton(
              icon: Image.asset(R.image.messageBadge),
              onPressed: () => Get.toNamed(AppRoutes.systemNotification))
        ],
      ),
      body: CustomScrollView(
        slivers: [
          SliverPadding(
            padding: EdgeInsets.symmetric(horizontal: R.dimen.dp10),
            sliver: SliverList(
              delegate:
                  SliverChildBuilderDelegate((BuildContext context, int i) {
                MessageEntity message = controller.messages[i];
                return GestureDetector(
                  onTap: () => Get.toNamed(AppRoutes.chat),
                  child: Container(
                    padding: EdgeInsets.only(top: R.dimen.dp24),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        CircleAvatar(
                          radius: R.dimen.dp42 / 2,
                          child: message.type == MessageType.system
                              ? Image.asset(R.image.messageAlarm)
                              : ChimeraImage(
                                  src: message.avatar!,
                                  fit: BoxFit.fill,
                                ),
                        ),
                        Expanded(
                          child: Container(
                            margin: EdgeInsets.only(left: R.dimen.dp18),
                            padding: EdgeInsets.only(bottom: R.dimen.dp24),
                            decoration: BoxDecoration(
                                border: Border(
                                    bottom: BorderSide(
                                        width: .5, color: R.color.ffdddddd))),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Row(
                                  children: [
                                    Text(
                                      message.username,
                                      style: TextStyle(
                                        fontSize: R.dimen.sp15,
                                      ),
                                    ),
                                    Container(
                                        margin:
                                            EdgeInsets.only(left: R.dimen.dp12),
                                        child: Text(
                                          "${message.company ?? ''}",
                                          style:
                                              TextStyle(fontSize: R.dimen.sp12),
                                        )),
                                    Spacer(),
                                    Text(
                                      "${message.createAt}",
                                      style: TextStyle(
                                          fontSize: R.dimen.sp10,
                                          color: R.color.ffaaaaaa),
                                    )
                                  ],
                                ),
                                Container(
                                  margin: EdgeInsets.only(top: R.dimen.dp10),
                                  child: Text(
                                    message.content,
                                    style: TextStyle(
                                        fontSize: R.dimen.sp12,
                                        color: R.color.ff666666),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                );
              }, childCount: controller.messages.length),
            ),
          ),
          SliverPadding(
            padding: EdgeInsets.symmetric(
                horizontal: R.dimen.dp10, vertical: R.dimen.dp20),
            sliver: SliverToBoxAdapter(
              child: Text(
                "一周前消息",
                style:
                    TextStyle(fontSize: R.dimen.sp15, color: R.color.ffcccccc),
              ),
            ),
          ),
          SliverPadding(
            padding: EdgeInsets.symmetric(horizontal: R.dimen.dp10),
            sliver: SliverList(
              delegate:
                  SliverChildBuilderDelegate((BuildContext context, int i) {
                MessageEntity message = controller.messages[i];
                return Container(
                  padding: EdgeInsets.only(top: R.dimen.dp24),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      CircleAvatar(
                        radius: R.dimen.dp42 / 2,
                        child: message.type == MessageType.system
                            ? Image.asset(R.image.messageAlarm)
                            : ChimeraImage(
                                src: message.avatar!,
                                fit: BoxFit.fill,
                              ),
                      ),
                      Expanded(
                        child: Container(
                          margin: EdgeInsets.only(left: R.dimen.dp18),
                          padding: EdgeInsets.only(bottom: R.dimen.dp24),
                          decoration: BoxDecoration(
                              border: Border(
                                  bottom: BorderSide(
                                      width: .5, color: R.color.ffdddddd))),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Row(
                                children: [
                                  Text(
                                    message.username,
                                    style: TextStyle(
                                      fontSize: R.dimen.sp15,
                                    ),
                                  ),
                                  Container(
                                      margin:
                                          EdgeInsets.only(left: R.dimen.dp12),
                                      child: Text(
                                        "${message.company}",
                                        style:
                                            TextStyle(fontSize: R.dimen.sp12),
                                      ))
                                ],
                              ),
                              Container(
                                margin: EdgeInsets.only(top: R.dimen.dp10),
                                child: Text(
                                  message.content,
                                  style: TextStyle(
                                      fontSize: R.dimen.sp12,
                                      color: R.color.ff666666),
                                ),
                              ),
                            ],
                          ),
                        ),
                      )
                    ],
                  ),
                );
              }, childCount: controller.messages.length),
            ),
          )
        ],
      ),
    );
  }
}
